﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using CI.Models;
using CI.Models.Data;
using CI.Models.Production;
using CI.Models.Production.Interfaces;
using CI.Services;
using CI.ViewModels.Diagramming;
using CI.ViewModels.Commerce;
using CI.ViewModels.Interfaces;
using Microsoft.Practices.ServiceLocation;
using GongSolutions.Wpf.DragDrop;
using System.Windows;
using QuickGraph;

namespace CI.ViewModels.Industry
{
    public class IndustrySheetViewModel : DiagramViewModel
    {
        private static IStaticDataRepository<Item> _itemDataRepository = ServiceLocator.Current.GetInstance<IStaticDataRepository<Item>>();

        public IndustrySheetViewModel()
        {
            Options = new IndustrySheetOptionsViewModel();

            SelectorModels = new ObservableCollection<IItemSelectorViewModel>
                                 {
                                     new OwnerSelectorViewModel("Owners",this),
                                     new JobSelectorViewModel("Jobs",this),
                                     new SchematicItemSelectorViewModel(
                                         _itemDataRepository,
                                         "Planetary Interaction", this),
                                     new Tech1ItemSelectorViewModel(
                                         _itemDataRepository,
                                         "Orbital Manufacturing - Tech I", this),
                                     new Tech2ItemSelectorViewModel(
                                         _itemDataRepository,
                                         "Orbital Manufacturing - Tech II", this),
                                     new Tech3ItemSelectorViewModel(
                                         _itemDataRepository,
                                         "Orbital Manufacturing - Tech III", this)
                                 };

            Model = new JobModel();

            WireModel();
        }

        public override void DragOver(IDropInfo dropInfo)
        {
            var data = dropInfo.Data;

            if (data is ICharacter)
            {
                dropInfo.Effects = DragDropEffects.Copy;
            }
            else if (data is ICorporation)
            {
                dropInfo.Effects = DragDropEffects.Copy;
            }
            else
            {
                dropInfo.IsNotHandled = true;
            }
        }

        public override void Drop(IDropInfo dropInfo)
        {
            var data = dropInfo.Data;

            if (data is ICharacter || data is ICorporation)
                Model.AddNode(data);
            else
                dropInfo.IsNotHandled = true;
        }

        public IndustrySheetOptionsViewModel Options { get; private set; }
        public ObservableCollection<IItemSelectorViewModel> SelectorModels { get; private set; }

    }
}